<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>NVTX C API Reference: Synchronization</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectalign">
   <div id="projectname">NVTX C API Reference<span id="projectnumber">&#160;v3</span>
   </div>
   <div id="projectbrief">NVIDIA Tools Extension Library</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.8 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>

</div><!-- top -->
<div><div class="header">
  <div class="headertitle"><div class="title">Synchronization</div></div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>This section covers a subset of the API that allow users to track additional synchronization details of their application. Naming OS synchronization primitives may allow users to better understand the data collected by traced synchronization APIs. Additionally, a user defined synchronization object can allow the users to to tell the tools when the user is building their own synchronization system that do not rely on the OS to provide behaviors and instead use techniques like atomic operations and spinlocks.</p>
<p>See module <a class="el" href="group___s_y_n_c_h_r_o_n_i_z_a_t_i_o_n.html">Synchronization</a> for details.</p>
<dl class="section user"><dt>Example</dt><dd>Instrument a mutex class: <div class="fragment"><div class="line"><span class="keyword">class </span>MyMutex</div>
<div class="line">{</div>
<div class="line">    <span class="keyword">volatile</span> <span class="keywordtype">long</span> bLocked;</div>
<div class="line">    <a class="code hl_typedef" href="group___s_y_n_c_h_r_o_n_i_z_a_t_i_o_n.html#ga79ab2a04ba725255a14f1d2a34b92f9f">nvtxSyncUser_t</a> hSync;</div>
<div class="line"><span class="keyword">public</span>:</div>
<div class="line">    MyMutex(<span class="keyword">const</span> <span class="keywordtype">char</span>* name, nvtxDomainHandle_t d) {</div>
<div class="line">         bLocked = 0;</div>
<div class="line"> </div>
<div class="line">         nvtxSyncUserAttributes_t attribs = { 0 };</div>
<div class="line">         attribs.version = <a class="code hl_define" href="nv_tools_ext_8h.html#a270c1573fb02bc9f15825438913a255c">NVTX_VERSION</a>;</div>
<div class="line">         attribs.size = NVTX_SYNCUSER_ATTRIB_STRUCT_SIZE;</div>
<div class="line">         attribs.messageType = <a class="code hl_enumvalue" href="group___g_e_n_e_r_a_l.html#ggaf74d5ab5269ee3c1de7aa0059ca31c46aad30a1fb6651b7f2c36d8d19ade74576">NVTX_MESSAGE_TYPE_ASCII</a>;</div>
<div class="line">         attribs.message.ascii = name;</div>
<div class="line">         hSync = <a class="code hl_function" href="group___s_y_n_c_h_r_o_n_i_z_a_t_i_o_n.html#gafa5155c0890472bcaaba59e8a20c397e">nvtxDomainSyncUserCreate</a>(d, &amp;attribs);</div>
<div class="line">    }</div>
<div class="line"> </div>
<div class="line">    ~MyMutex() {</div>
<div class="line">         <a class="code hl_function" href="group___s_y_n_c_h_r_o_n_i_z_a_t_i_o_n.html#gadcb0093d514169e0ef8e77df268a05a3">nvtxDomainSyncUserDestroy</a>(hSync);</div>
<div class="line">    }</div>
<div class="line"> </div>
<div class="line">    <span class="keywordtype">bool</span> Lock() {</div>
<div class="line">         <a class="code hl_function" href="group___s_y_n_c_h_r_o_n_i_z_a_t_i_o_n.html#ga095b4608933461c8be0197d91536f799">nvtxDomainSyncUserAcquireStart</a>(hSync);</div>
<div class="line">         <span class="keywordtype">bool</span> acquired = __sync_bool_compare_and_swap(&amp;bLocked, 0, 1); <span class="comment">// atomic compiler intrinsic</span></div>
<div class="line"> </div>
<div class="line">         <span class="keywordflow">if</span> (acquired) {</div>
<div class="line">             <a class="code hl_function" href="group___s_y_n_c_h_r_o_n_i_z_a_t_i_o_n.html#ga6ea2a313cad77c58dc4150fdd08ef72c">nvtxDomainSyncUserAcquireSuccess</a>(hSync);</div>
<div class="line">         }</div>
<div class="line">         <span class="keywordflow">else</span> {</div>
<div class="line">             <a class="code hl_function" href="group___s_y_n_c_h_r_o_n_i_z_a_t_i_o_n.html#ga0e55c70eb9e00dab800a1f8d88a8ef64">nvtxDomainSyncUserAcquireFailed</a>(hSync);</div>
<div class="line">         }</div>
<div class="line">         <span class="keywordflow">return</span> acquired;</div>
<div class="line">    }</div>
<div class="line"> </div>
<div class="line">    <span class="keywordtype">void</span> Unlock() {</div>
<div class="line">         <a class="code hl_function" href="group___s_y_n_c_h_r_o_n_i_z_a_t_i_o_n.html#ga4524252698484b2af060b4b37bac6840">nvtxDomainSyncUserReleasing</a>(hSync);</div>
<div class="line">         bLocked = <span class="keyword">false</span>;</div>
<div class="line">    }</div>
<div class="line">};</div>
<div class="ttc" id="agroup___g_e_n_e_r_a_l_html_ggaf74d5ab5269ee3c1de7aa0059ca31c46aad30a1fb6651b7f2c36d8d19ade74576"><div class="ttname"><a href="group___g_e_n_e_r_a_l.html#ggaf74d5ab5269ee3c1de7aa0059ca31c46aad30a1fb6651b7f2c36d8d19ade74576">NVTX_MESSAGE_TYPE_ASCII</a></div><div class="ttdeci">@ NVTX_MESSAGE_TYPE_ASCII</div><div class="ttdef"><b>Definition</b> <a href="nv_tools_ext_8h_source.html#l00450">nvToolsExt.h:450</a></div></div>
<div class="ttc" id="agroup___s_y_n_c_h_r_o_n_i_z_a_t_i_o_n_html_ga095b4608933461c8be0197d91536f799"><div class="ttname"><a href="group___s_y_n_c_h_r_o_n_i_z_a_t_i_o_n.html#ga095b4608933461c8be0197d91536f799">nvtxDomainSyncUserAcquireStart</a></div><div class="ttdeci">NVTX_DECLSPEC void NVTX_API nvtxDomainSyncUserAcquireStart(nvtxSyncUser_t handle)</div><div class="ttdoc">Signal to tools that an attempt to acquire a user defined synchronization object.</div></div>
<div class="ttc" id="agroup___s_y_n_c_h_r_o_n_i_z_a_t_i_o_n_html_ga0e55c70eb9e00dab800a1f8d88a8ef64"><div class="ttname"><a href="group___s_y_n_c_h_r_o_n_i_z_a_t_i_o_n.html#ga0e55c70eb9e00dab800a1f8d88a8ef64">nvtxDomainSyncUserAcquireFailed</a></div><div class="ttdeci">NVTX_DECLSPEC void NVTX_API nvtxDomainSyncUserAcquireFailed(nvtxSyncUser_t handle)</div><div class="ttdoc">Signal to tools of failure in acquiring a user defined synchronization object This should be called a...</div></div>
<div class="ttc" id="agroup___s_y_n_c_h_r_o_n_i_z_a_t_i_o_n_html_ga4524252698484b2af060b4b37bac6840"><div class="ttname"><a href="group___s_y_n_c_h_r_o_n_i_z_a_t_i_o_n.html#ga4524252698484b2af060b4b37bac6840">nvtxDomainSyncUserReleasing</a></div><div class="ttdeci">NVTX_DECLSPEC void NVTX_API nvtxDomainSyncUserReleasing(nvtxSyncUser_t handle)</div><div class="ttdoc">Signal to tools of releasing a reservation on user defined synchronization object This should be call...</div></div>
<div class="ttc" id="agroup___s_y_n_c_h_r_o_n_i_z_a_t_i_o_n_html_ga6ea2a313cad77c58dc4150fdd08ef72c"><div class="ttname"><a href="group___s_y_n_c_h_r_o_n_i_z_a_t_i_o_n.html#ga6ea2a313cad77c58dc4150fdd08ef72c">nvtxDomainSyncUserAcquireSuccess</a></div><div class="ttdeci">NVTX_DECLSPEC void NVTX_API nvtxDomainSyncUserAcquireSuccess(nvtxSyncUser_t handle)</div><div class="ttdoc">Signal to tools of success in acquiring a user defined synchronization object This should be called a...</div></div>
<div class="ttc" id="agroup___s_y_n_c_h_r_o_n_i_z_a_t_i_o_n_html_ga79ab2a04ba725255a14f1d2a34b92f9f"><div class="ttname"><a href="group___s_y_n_c_h_r_o_n_i_z_a_t_i_o_n.html#ga79ab2a04ba725255a14f1d2a34b92f9f">nvtxSyncUser_t</a></div><div class="ttdeci">struct nvtxSyncUser * nvtxSyncUser_t</div><div class="ttdoc">User Defined Synchronization Object Handle . .</div><div class="ttdef"><b>Definition</b> <a href="nv_tools_ext_sync_8h_source.html#l00175">nvToolsExtSync.h:175</a></div></div>
<div class="ttc" id="agroup___s_y_n_c_h_r_o_n_i_z_a_t_i_o_n_html_gadcb0093d514169e0ef8e77df268a05a3"><div class="ttname"><a href="group___s_y_n_c_h_r_o_n_i_z_a_t_i_o_n.html#gadcb0093d514169e0ef8e77df268a05a3">nvtxDomainSyncUserDestroy</a></div><div class="ttdeci">NVTX_DECLSPEC void NVTX_API nvtxDomainSyncUserDestroy(nvtxSyncUser_t handle)</div><div class="ttdoc">Destroy a user defined synchronization object This is used to track non-OS synchronization working wi...</div></div>
<div class="ttc" id="agroup___s_y_n_c_h_r_o_n_i_z_a_t_i_o_n_html_gafa5155c0890472bcaaba59e8a20c397e"><div class="ttname"><a href="group___s_y_n_c_h_r_o_n_i_z_a_t_i_o_n.html#gafa5155c0890472bcaaba59e8a20c397e">nvtxDomainSyncUserCreate</a></div><div class="ttdeci">NVTX_DECLSPEC nvtxSyncUser_t NVTX_API nvtxDomainSyncUserCreate(nvtxDomainHandle_t domain, const nvtxSyncUserAttributes_t *attribs)</div><div class="ttdoc">Create a user defined synchronization object This is used to track non-OS synchronization working wit...</div></div>
<div class="ttc" id="anv_tools_ext_8h_html_a270c1573fb02bc9f15825438913a255c"><div class="ttname"><a href="nv_tools_ext_8h.html#a270c1573fb02bc9f15825438913a255c">NVTX_VERSION</a></div><div class="ttdeci">#define NVTX_VERSION</div><div class="ttdef"><b>Definition</b> <a href="nv_tools_ext_8h_source.html#l00177">nvToolsExt.h:177</a></div></div>
</div><!-- fragment --></dd></dl>
<dl class="section version"><dt>Version</dt><dd>NVTX_VERSION_2 </dd></dl>
</div></div><!-- contents -->
</div><!-- PageDoc -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.8
</small></address>
</body>
</html>
